# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui, uic

mavlinkParaDlgui = 'mirrorSerialSetting.ui'
Ui_Dlg, QtBaseClass = uic.loadUiType(mavlinkParaDlgui)

class mirrorSerialSettingDlg(QtGui.QDialog, Ui_Dlg):
    def __init__(self,data=None):
        QtGui.QDialog.__init__(self)
        Ui_Dlg.__init__(self)
        self.setupUi(self)
        self.initialData(data)
    def initialData(self,data):
        self.data  = data
    @staticmethod
    def getPara(data=None):
        '''
            data structure:
            {
                "currentPort": str(),
                "avaliablePorts":list(),
                "bidirection":bool,
                "mavlinkStyle":bool,
                'parent':parent
            }
        
        '''
        
        dialog = mirrorSerialSettingDlg(data['parent'])
        dialog.currenCOMLabel.setText(data['currentPort'])
        dialog.mirrorserialList.addItems(data['avaliablePorts'])
        dialog.isbidirectCheckBox.setChecked(data['bidirection'])   
        dialog.mavlinkRouteMethodButton.setChecked(data['mavlinkStyle'])
        
        result = dialog.exec_()
        returnedData={
            'mirrorPort':str(dialog.mirrorserialList.currentText()),
            'bidirection':dialog.isbidirectCheckBox.isChecked(),
            'mavlinkStyle':dialog.mavlinkRouteMethodButton.isChecked(),
            'disableMirror':dialog.mavlinkMirrorDisableBtn.isChecked()
        }
        return (returnedData, result == QtGui.QDialog.Accepted)

if __name__ == "__main__":  
    app = QtGui.QApplication(sys.argv)
    window = mirrorSerialSettingDlg()
    window.show()
    sys.exit(app.exec_())